package example.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class BaseDao {
    /**
     * 获取数据库连接对象
     */
    public static Connection getConnection() {
        Connection connection = null;
        String driver = ConfigManager.getInstance().getValue("jdbc.driver");
        String url = ConfigManager.getInstance().getValue("jdbc.url");
        String username = ConfigManager.getInstance().getValue("jdbc.username");
        String password = ConfigManager.getInstance().getValue("jdbc.password");
        try {
            Class.forName(driver);
            connection = DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return connection;
    }
}
